'use strict';
exports.main = async (event, context) => {
	const { data } = event
	const db = uniCloud.database()
	const dbCmd = db.command
	const todos = db.collection('post-data')

	try {
		// 对images合并、title覆盖
		await todos.doc(data._id)
		.update({
			images: dbCmd.push(data.images),
			title: data.title
		})

		return {
			success: true,
			message: '数据更新成功'
		}
	} catch (err) {
		console.error(err)
		return {
			success: false,
			message: '数据更新失败',
			error: err
		}
	}
}
